using System;
using System.Drawing;
using System.Windows.Forms;

namespace RebelStar.Engine.GameView
{
    public class GameViewPanel : Panel, IServiceProvider
    {
        private GraphicsDeviceService graphicsDeviceService;

        public GameViewPanel()
        {
            this.SetStyle(ControlStyles.Selectable, true);
            this.DoubleBuffered = true;
        }

        public void Initialize()
        {
            this.graphicsDeviceService = new GraphicsDeviceService(this);
            this.graphicsDeviceService.CreateDevice();
        }
        new public bool DoubleBuffered
        {
            get
            {
                return this.GetStyle(ControlStyles.OptimizedDoubleBuffer);
            }
            set
            {
                this.SetStyle(
                    ControlStyles.ResizeRedraw |
                    ControlStyles.UserPaint |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.AllPaintingInWmPaint, value);
            }
        }

        #region IServiceProvider Members
        public new object GetService(Type serviceType)
        {
            if (serviceType == typeof(Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService))
            {
                return this.graphicsDeviceService;
            }
            else
            {
                return base.GetService(serviceType);
            }
        }
        #endregion

        internal GraphicsDeviceService GraphicsDeviceService
        {
            get { return graphicsDeviceService; }
        }
    }
}